#!/usr/bin/env python
# -*- coding:GBK -*-
import os
import os.path
from ServiceUtil import ParamUtil
from ServiceUtil import LinkConst
def GetPreferInfo(servNbrList):
    paramUtil=ParamUtil()
    resultList=[]
    for servNbr in servNbrList:
       paramList=[]
       paramList.append(servNbr)
       paramList.append('')
       paramList.append('5')
       serviceName='GetPreferInfo'
       outputParam=paramUtil.invoke(serviceName,paramList,URL)
       if outputParam.is_success():
           tables=outputParam.get_tables()
           table1=tables.get_first_table()
           rowList=table1.get_row_list()
           strValueList=[]
           strValueMap={}
           for row in rowList:
              strValueList.append(row.get_one_column(2).get_value())
           strValueMap['mesg']='|'.join(strValueList)
           strValueMap['serNbr']=servNbr
           convertUnicodeToStr(strValueMap)
           print strValueMap['serNbr']+','+strValueMap['mesg']
           resultList.append(strValueMap)
    return resultList

def convertUnicodeToStr(unicodeMap):
    for key in unicodeMap.keys():
        if isinstance(unicodeMap[key],unicode):
            unicodeMap[key]=unicodeMap[key].encode('GBK')
if __name__ == '__main__':
    tempFile=open('temp.txt')
    URL='http://134.128.196.10:9081/iservuc/ServiceGate/SimpleXMLGate'
    servNbrList=[]
    for line in tempFile:
        servNbrList.append(line.strip())
    resultList=GetPreferInfo(servNbrList)
    resultFile=open('result.txt','wb')
    for strValueMap in resultList:
        linestr=strValueMap['serNbr']+','+strValueMap['mesg']+'\n'
        resultFile.write(linestr)
    resultFile.close()
    

